
/****************************************************************************
  From Qt Examples
****************************************************************************/

#include "sslserver.h"
#include "sslserverthread.h"
#include <QDebug>
#include <QtNetwork>
#include <stdlib.h>

SSLServer::SSLServer(QObject *parent)
    : QTcpServer(parent)
{

}


QString SSLServer::getCMSG()
{
    return message;
}

void SSLServer::setMsg(QString msg)
{
    message = msg;
}



void SSLServer::incomingConnection(int socketDescriptor)
{

    qDebug() << socketDescriptor << " Connecting...";

    //For reading the data from the client
   // connect(connection, SIGNAL(readyRead()), this, SLOT(ReadCMsg()));
    SSLThread *thread = new SSLThread(socketDescriptor, message, this);
    connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
    connect(thread,SIGNAL(clientMessage(QString)),this,SLOT(getMSG(QString)));
    connect(this,SIGNAL(sendMsgToThread(QString)),thread,SLOT(sendData(QString)));
    thread->start();

}

void SSLServer::getMSG(QString msg)
{
    qDebug() << "Client message: " << msg;
    message = msg;
    emit transferMessage(message);
}


void SSLServer::carryMsgToThread(QString msg)
{

    emit sendMsgToThread(msg);

}
